package com.grouplay.dao;

import com.grouplay.entity.Information;
import com.grouplay.entity.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository("informationDao")
public interface IInformationDao {
    @Insert("insert into `information` (sourceUid, targetUid, message, date, hasBeenLooked) values (#{sourceUid}, #{targetUid}, #{message}, #{date}, #{hasBeenLooked})")
    void insert(Information information);

    @Select("select i.id, i.sourceUid, i.targetUid, i.message, i.date, i.hasBeenLooked, us.name sourceName, #{name} targetName " +
            "from `information` i, `user` us " +
            "where " +
            "i.targetUid = #{id} and i.sourceUid = us.id " +
            "order by i.date desc limit 10")
    List<Information> findTenInformationByUser(User user);

    @Update("update `information` set hasBeenLooked = 1 where id = #{id} and targetUid = #{targetUid}")
    void setHasBeenLookedByIdAndTargetId(Information information);
}
